﻿using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using Autodesk.Revit.UI;
using YArchitech.Revit;

namespace YJKAreaCutter.Utils
{
	public class GifFormOperator
	{
		public static void Start(string strTip = "")
		{
			if (GifFormOperator.m_GifForm == null && GifFormOperator.m_Thread == null)
			{
				GifFormOperator.m_GifForm = new GifForm();
				if (!string.IsNullOrEmpty(strTip))
				{
					GifFormOperator.m_GifForm.Tip = strTip;
				}
                //GifFormOperator.m_Thread = new System.Threading.Thread(delegate
                //{
                //    Application.Run(GifFormOperator.m_GifForm);
                //});
                //GifFormOperator.m_Thread.Start();
			}
		}

		public static void SetCenterPosition(UIView view)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			RevitViewExtension.GetRevitWndRectangle(view, ref num, ref num2, ref num3, ref num4);
			int num5 = num3 - num;
			int num6 = num2 - num4;
			GifFormOperator.m_GifForm.Location = new System.Drawing.Point(num + num5 / 2, num2 - num6 / 2);
		}

		public static void end()
		{
			if (GifFormOperator.m_GifForm != null && GifFormOperator.m_Thread != null)
			{
				GifFormOperator.m_GifForm.CloseThread();
				GifFormOperator.m_GifForm.Close();
				GifFormOperator.m_GifForm.Dispose();
				GifFormOperator.m_Thread.Abort();
				GifFormOperator.m_GifForm = null;
				GifFormOperator.m_Thread = null;
			}
		}

		private static GifForm m_GifForm;

		private static Thread m_Thread;
	}
}
